//
//  CZSwiftSingle.swift
//  weibo
//
//  Created by Apple on 16/3/9.
//  Copyright © 2016年 KY. All rights reserved.
//

import UIKit

class CZSwiftSingle: NSObject {

    static var onceToken: dispatch_once_t = 0
    static var instance: CZSwiftSingle?
    //  仿照OC单例
    class func sharedSwiftSingle() -> CZSwiftSingle {
        
        //  不能在类内部使用static,放在外面写
        
        dispatch_once(&onceToken) { () -> Void in
            instance = CZSwiftSingle()
        }
        
        return instance!
    }
    
    //  swift 单例的写法，static let
    static let sharedSwiftSingleInstance = CZSwiftSingle()
    
    //  也可以使用闭包
    static let sharedSwiftSingleInstance1: CZSwiftSingle = {
        let instance = CZSwiftSingle()
        return instance
    }()
    
}
